const app=getApp();
Page({


  data: {
    bannerList:[],
    typeList:[],
    goodsList:[]
  },

  onLoad: function (options) {
    // 获取轮播图数据库记录
    this.getBanners();
    this.getCategory();
    this.getGoodsList();
  },
  onShow(){
    this.getGoodsList();
  },
  // 获取轮播图数据库记录
  getBanners() {
    wx.request({
      url: `${app.globalData.baseurl}home/banner`,
      method: 'GET',
      success: (res) => {
        if (res.statusCode == 200) {
          this.setData({
            bannerList: res.data
          });
          // console.log(this.data.bannerList);
        }
      },
      fail: (err) => {
        console.log('error!');
      }
    })
  },
  toBannerDetail(event){
    console.log(event.currentTarget.dataset.id);
    let id=event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../index/bannerDetail/bannerDetail?bannerId='+id,
    })
  },
  getCategory(){
    wx.request({
      url: `${app.globalData.baseurl}category/`,
      method: 'GET',
      success: (res) => {
        if (res.statusCode == 200) {
          this.setData({
            typeList: res.data
          });
          // console.log(this.data.typeList);
        }
      },
      fail: (err) => {
        console.log('error!');
      }
    })
  },
  getGoodsList(){
    wx.request({
      url: `${app.globalData.baseurl}goods/`,
      method: 'GET',
      success: (res) => {
        if (res.statusCode == 200) {
          this.setData({
            goodsList: res.data
          });
          console.log(this.data.goodsList);
        }
      },
      fail: (err) => {
        console.log('error!');
      }
    })
  },
  toGoodDetail(event){
    console.log(event.currentTarget.dataset.id);
    let id=event.currentTarget.dataset.id;
    wx.navigateTo({
      // url: '../goodDetail/goodDetail?goodsId='+id,
      url:'../goodDetail/goodDetail?goodsId='+id,
    })
  },
  toTypeDetail(event){
    console.log(event.currentTarget.dataset.id);
    let id=event.currentTarget.dataset.id;
    wx.navigateTo({
      url:'/pages/index/typeDetail/typeDetail?sortid='+id
      // url:'../index/typeDetail/typeDetail?sortid='+id,
    })
  },
  toSearch(){
    wx.navigateTo({
      url:'../index/search/search'
    })
  }

})